package com.yanqu.road.server.pb;

import com.yanqu.road.entity.autodata.chuhan.config.*;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.logic.activity.chuhan.ChuHanConfig;
import com.yanqu.road.pb.activity.ChuHanProto;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.utils.date.DateHelper;

import java.util.ArrayList;
import java.util.List;

public class ChuHanPb {

    public static ChuHanProto.ChuHanSyncConfigRespMsg.Builder parseChuHanSyncConfigRespMsg(ChuHanConfig config, String language) {
        ChuHanProto.ChuHanSyncConfigRespMsg.Builder builder = ChuHanProto.ChuHanSyncConfigRespMsg.newBuilder();
        for (ChuHanBuffTypeConfig buffTypeConfig : config.getBuffTypeConfigMap().values()) {
            builder.addBuffTypeConfig(ChuHanPb.parseChuHanBuffTypeConfigMsg(buffTypeConfig, language));
        }
        for (ChuHanCityTypeConfig cityTypeConfig : config.getCityTypeConfigMap().values()) {
            builder.addCityTypeConfig(ChuHanPb.parseChuHanCityTypeConfigMsg(cityTypeConfig, language));
        }
        for (ChuHanCityConfig cityConfig : config.getCityConfigMap().values()) {
            builder.addCityConfig(ChuHanPb.parseChuHanCityConfigMsg(cityConfig, language));
        }
        for (ChuHanNpcEventConfig npcEventConfig : config.getNpcEventConfigMap().values()) {
            builder.addNpcEventConfig(ChuHanPb.parseChuHanNpcEventConfigMsg(npcEventConfig));
        }
        for (ChuHanTitleConfig titleConfig : config.getTitleConfigMap().values()) {
            builder.addTitleConfig(ChuHanPb.parseChuHanTitleConfigMsg(titleConfig, language));
        }
        return builder;
    }

    public static ChuHanProto.ChuHanBuffTypeConfigMsg.Builder parseChuHanBuffTypeConfigMsg(ChuHanBuffTypeConfig config, String language) {
        ChuHanProto.ChuHanBuffTypeConfigMsg.Builder builder = ChuHanProto.ChuHanBuffTypeConfigMsg.newBuilder();
        builder.setId(config.getId());
        builder.setBuffType(config.getType());
        builder.setIcon(config.getIcon());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setDesc(ServerLanguageMgr.getContent(config.getDesc(), language));
        builder.setBuffEffect(config.getBuffEffect());
        return builder;
    }

    public static ChuHanProto.ChuHanCityTypeConfigMsg.Builder parseChuHanCityTypeConfigMsg(ChuHanCityTypeConfig config, String language) {
        ChuHanProto.ChuHanCityTypeConfigMsg.Builder builder = ChuHanProto.ChuHanCityTypeConfigMsg.newBuilder();
        builder.setCityType(config.getType());
        builder.setIcon(config.getIcon());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setFoodProduction(config.getFoodProduction());
        builder.setTeamNum(config.getTeamNum());
        builder.setSoldierNum(config.getSoldierNum());
        builder.setAddition(config.getAddition());
        builder.setBuffEffect(String.valueOf(config.getBuffEffect()));
        builder.setCampScore(config.getCampPoint());
        builder.setExtraTeamNum(config.getExtraTeamNum());
        builder.setExtraTeamNumMax(config.getExtraTeamNumMax());
        return builder;
    }

    public static ChuHanProto.ChuHanCityConfigMsg.Builder parseChuHanCityConfigMsg(ChuHanCityConfig config, String language) {
        ChuHanProto.ChuHanCityConfigMsg.Builder builder = ChuHanProto.ChuHanCityConfigMsg.newBuilder();
        builder.setCityId(config.getId());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setMapType(config.getMapType());
        builder.setCityType(config.getType());
        builder.setInitialCamp(config.getInitialCamp());
        builder.setShowType(config.getShowType());
        builder.setBuffId(config.getBuffId());
        builder.setOrderTargetType(config.getOrderTargetType());
        builder.setMapCamp(config.getMapCamp());
        builder.setSpecialAddition(config.getSpecialAddition());
        return builder;
    }

    public static ChuHanProto.ChuHanNpcEventConfigMsg.Builder parseChuHanNpcEventConfigMsg(ChuHanNpcEventConfig config) {
        ChuHanProto.ChuHanNpcEventConfigMsg.Builder builder = ChuHanProto.ChuHanNpcEventConfigMsg.newBuilder();
        builder.setEventId(config.getId());
        builder.setEventType(config.getType());
        builder.setIcon(config.getIcon());
        builder.setRewards(config.getRewards());
        return builder;
    }


    public static ChuHanProto.ChuHanTitleConfigMsg.Builder parseChuHanTitleConfigMsg(ChuHanTitleConfig config, String language) {
        ChuHanProto.ChuHanTitleConfigMsg.Builder builder = ChuHanProto.ChuHanTitleConfigMsg.newBuilder();
        builder.setTitleId(config.getId());
        builder.setIcon(config.getIcon());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setType(config.getType());
        builder.setEffect(config.getEffect());
        builder.setRewards(config.getRewards());
        return builder;
    }

    /**
     * 获取战力同步门客列表
     */
    public static List<ChuHanProto.ChuHanPatronsTempMsg> parseChuHanPatronsListMsg(List<UserPatrons> userPatronsList) {
        List<ChuHanProto.ChuHanPatronsTempMsg> list = new ArrayList<>();
        for (UserPatrons userPatrons : userPatronsList) {
            ChuHanProto.ChuHanPatronsTempMsg.Builder tempBuilder = ChuHanProto.ChuHanPatronsTempMsg.newBuilder();
            tempBuilder.setId(userPatrons.getPatronsId());
            tempBuilder.setSkin(userPatrons.getSkinId());
            tempBuilder.setAbility(userPatrons.getAbility().longValue());
            list.add(tempBuilder.build());
        }
        return list;
    }

}
